package es.ucm.is.www.GUI.client.technologies;

import java.util.ArrayList;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.ServiceDefTarget;

import es.ucm.is.www.GUI.client.buildings.BuildingsService;
import es.ucm.is.www.GUI.client.buildings.BuildingsServiceAsync;
import es.ucm.is.www.GUI.client.callbacks.AsyncCallbackBoolean;

public class ConexionServletTechnologies {

	private static String URLmodulo = GWT.getModuleBaseURL() + "servletTechnologies";
	
	public ConexionServletTechnologies(){
		
	}
	
	public long equationTechnology(int level, float modifier){
		/*TechnologiesServiceAsync servicio = (TechnologiesServiceAsync) GWT.create(TechnologiesService.class);
		ServiceDefTarget endpoint = (ServiceDefTarget) servicio;
		endpoint.setServiceEntryPoint(URLmodulo);*/
		long l = 0;
		
		/*AsyncCallbackLong callback = new AsyncCallbackLong();
		servicio.equationTechnology(level, modifier, callback);
		l = callback.getResult();*/
		return l;
	}
	
	public long getSubLevelTechnology(long founds,long startTime, float modifier, Long cash,Integer level,Long totalNivel){
		/*TechnologiesServiceAsync servicio = (TechnologiesServiceAsync) GWT.create(TechnologiesService.class);
		ServiceDefTarget endpoint = (ServiceDefTarget) servicio;
		endpoint.setServiceEntryPoint(URLmodulo);*/
		long l = 0;
		/*
		AsyncCallbackLong callback = new AsyncCallbackLong();
		servicio.getSubLevelTechnology(founds, startTime, modifier, cash, level, totalNivel, callback);
		l = callback.getResult();*/
		return l;
	}
	
	public boolean stopTechnology(String owner, int idTech){
		/*TechnologiesServiceAsync servicio = (TechnologiesServiceAsync) GWT.create(TechnologiesService.class);
		ServiceDefTarget endpoint = (ServiceDefTarget) servicio;
		endpoint.setServiceEntryPoint(URLmodulo);*/
		boolean b = false;
		
		/*AsyncCallbackBoolean callback = new AsyncCallbackBoolean();
		servicio.stopTechnology(owner, idTech, callback);
		b = callback.getResult();*/
		return b;
	}
	
	public boolean startTechnology(String owner, int idtech, long founds){
		/*TechnologiesServiceAsync servicio = (TechnologiesServiceAsync) GWT.create(TechnologiesService.class);
		ServiceDefTarget endpoint = (ServiceDefTarget) servicio;
		endpoint.setServiceEntryPoint(URLmodulo);*/
		boolean b = false;
		
		/*AsyncCallbackBoolean callback = new AsyncCallbackBoolean();
		servicio.startTechnology(owner, idtech, founds, callback);
		b = callback.getResult();*/
		return b;
	}
	
	public boolean createTechnologies(String owner){
		TechnologiesServiceAsync servicio = (TechnologiesServiceAsync) GWT.create(TechnologiesService.class);
		ServiceDefTarget endpoint = (ServiceDefTarget) servicio;
		endpoint.setServiceEntryPoint(URLmodulo);
		boolean b;
		
		AsyncCallbackBoolean callback = new AsyncCallbackBoolean();
		servicio.createTechnologies(owner, callback);
		b = callback.getResult();
		return b;
	}
	
	public boolean changeFounds(String owner, int idtech, long newFounds){
		TechnologiesServiceAsync servicio = (TechnologiesServiceAsync) GWT.create(TechnologiesService.class);
		ServiceDefTarget endpoint = (ServiceDefTarget) servicio;
		endpoint.setServiceEntryPoint(URLmodulo);
		boolean b;
		
		AsyncCallbackBoolean callback = new AsyncCallbackBoolean();
		servicio.changeFounds(owner, idtech, newFounds, callback);
		b = callback.getResult();
		return b;
	}
	
	public boolean isStoppedTechnology(String owner, int idtech){
		TechnologiesServiceAsync servicio = (TechnologiesServiceAsync) GWT.create(TechnologiesService.class);
		ServiceDefTarget endpoint = (ServiceDefTarget) servicio;
		endpoint.setServiceEntryPoint(URLmodulo);
		boolean b;
		
		AsyncCallbackBoolean callback = new AsyncCallbackBoolean();
		servicio.isStoppedTechnology(owner, idtech, callback);
		b = callback.getResult();
		return b;
	}
	
	public ArrayList<TechnologyGUI> getAllTechnologies(String owner){
		TechnologiesServiceAsync servicio = (TechnologiesServiceAsync) GWT.create(TechnologiesService.class);
		ServiceDefTarget endpoint = (ServiceDefTarget) servicio;
		endpoint.setServiceEntryPoint(URLmodulo);
		ArrayList<TechnologyGUI> a = new ArrayList<TechnologyGUI>();
		
		/*AsyncCallbackArrayList callback = new AsyncCallbackArrayList();
		servicio.getAllTechnologies(owner, callback);
		a = callback.getResult();*/
		return a;
	}
	
	public TechnologyGUI updateTechnology(String owner,int id){
		TechnologiesServiceAsync servicio = (TechnologiesServiceAsync) GWT.create(TechnologiesService.class);
		ServiceDefTarget endpoint = (ServiceDefTarget) servicio;
		endpoint.setServiceEntryPoint(URLmodulo);
		TechnologyGUI t = new TechnologyGUI();
		
		/*AsyncCallbackTechnologyGUI callback = new AsyncCallbackTechnologyGUI();
		servicio.updateTechnology(owner, id, callback);
		t = callback.getResult();*/
		return t;
	}
	
}
